package com.film.admincontroller;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.film.service.ShowingsService;
import com.film.service.impl.ShowingsServiceImpl;
@WebServlet("/addShowings.do")
public class AddShowingsSController extends HttpServlet{
	private ShowingsService showingsService = new ShowingsServiceImpl();
	@Override
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		HttpSession session = request.getSession();
		String showingsTime = request.getParameter("showingsTime");
		String filmId = request.getParameter("filmId");
		String offId = request.getParameter("offId");
		String startTime = request.getParameter("startTime");
		String price = request.getParameter("price");
		System.out.println(showingsTime+"-->"+filmId+"-->"+offId+"-->"+startTime+"-->"+price);
		int result = showingsService.addFilmShowings(Integer.parseInt(filmId), showingsTime, startTime,Integer.parseInt(offId), Double.parseDouble(price));
		if(result == 1) {
			//成功
		}else if(result == 0){
			//失败
			session.setAttribute("addShowingsMsg","当前时间段该放映厅已有其他场次安排喔~");
		}else {
			//场次安排时间早于电影上映时间
			session.setAttribute("addShowingsMsg","抱歉，当前时间段电影还没上映呢，请把场次安排在电影上映之后吧");
		}
		response.sendRedirect("/film/filmShowings.do");
	}
}
